package com.example.springDemo.acutuator.health;

import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import org.springframework.stereotype.Component;

import java.util.HashMap;
@Component//表示这是个配置文件
//监控信息配置
//http://localhost:8080/actuator/health  配置这个页面信息
public class 健康信息HealthIndicator extends AbstractHealthIndicator {
    //前端会把HealthIndicator自动去掉
    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        if(1 == 1){ //业务代码
//            builder.up();//表示健康
            builder.status(Status.UP);//表示健康
        } else {
//            builder.down();//表示不健康
            //其他不健康的各种情况
            builder.status(Status.OUT_OF_SERVICE);
            builder.status(Status.DOWN);
            builder.status(Status.UNKNOWN);
        }

        builder.withDetails(new HashMap<>());
        builder.withDetail("K","V");
    }
}
